﻿Imports Newtonsoft.Json

Public Class DesignationManager

    Private manager As SQLManager

    Public Sub New()
        manager = New SQLManager
    End Sub

    Public Function getAllDesignation() As List(Of Designation)
        Dim designationArr As New List(Of Designation)
        Dim query As String = "SELECT * FROM `ref_designation`"
        Dim resultString As String = "" + manager.executeQuery(query)

        designationArr = JsonConvert.DeserializeObject(Of List(Of Designation))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If



        Return designationArr
    End Function


    Public Function retrieveDesignationById(ByVal id As Integer) As Designation
        Dim designationArr As New List(Of Designation)
        Dim designation As New Designation
        Dim query As String = "SELECT * FROM `ref_designation` WHERE id='" + id.ToString + "'"
        Dim resultString As String = "" + manager.executeQuery(query)

        designationArr = JsonConvert.DeserializeObject(Of List(Of Designation))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If

        For Each tempEmp As Designation In designationArr
            designation = tempEmp
            Exit For
        Next


        Return designation
    End Function

    Public Function retrieveDesignationByTitle(ByVal title As String) As Designation
        Dim designationArr As New List(Of Designation)
        Dim designation As New Designation
        Dim query As String = "SELECT * FROM `ref_designation` WHERE title='" + title + "'"
        Dim resultString As String = "" + manager.executeQuery(query)

        designationArr = JsonConvert.DeserializeObject(Of List(Of Designation))(resultString)


        For Each tempEmp As Designation In designationArr
            designation = tempEmp
            Exit For
        Next


        Return designation
    End Function



End Class
